<extend name="Public/base"/>

<block name="body">
    <div class="main-title">
        <h2>{$_title}</h2>
    </div>
    <notempty name="fund" >
    	<form action="{:U('Fund/editFund')}" method="post" class="form-horizontal">
    		<input type="hidden" name="id" value="{$fund.id}" />
    <else />
	    <form action="{:U('Fund/addFund')}" method="post" class="form-horizontal">
    </notempty>
        <!--<div class="form-item">-->
            <!--<label class="item-label">国家地区及代码<span class="check-tips"></span></label>-->
            <!--<div class="controls">-->
                <!--<select name="country_code" class="input-large">-->
            		<!--<foreach name="Think.config.COUNTRY_CODE" key="key" item="val">-->
	            		<!-- -->
	            		<!--<notempty name="fund">-->
		            		<!--<if condition="$key eq $fund['country_code']">-->
			           		<!--<option value="{$key}" selected>{$val}</option>-->
				           	<!--<else />-->
		            			<!--<option value="{$key}">{$val}</option>-->
		            		<!--</if>-->
            			<!--<else />-->
            				<!--<option value="{$key}">{$val}</option>-->
            			<!--</notempty>-->
            			<!-- -->
            		<!--</foreach>-->
            	<!--</select>-->
            <!--</div>-->
        <!--</div>-->
        <!--<div class="form-item">-->
            <!--<label class="item-label">基金代码<span class="check-tips">（证券投资基金所在的交易所公布的代码）</span></label>-->
            <!--<div class="controls">-->
            	<!--<input type="text" class="text input-large" name="fund_code" value="{$fund.fund_code|default=''}"/>-->
            <!--</div>-->
        <!--</div>-->
        <!--<div class="form-item">-->
            <!--<label class="item-label">基金简称<span class="check-tips">（以交易所公布的基金简称为准）</span></label>-->
            <!--<div class="controls">-->
            	<!--<input type="text" class="text input-large" name="fund_abb" value="{$fund.fund_abb|default=''}"/>-->
            <!--</div>-->
        <!--</div>-->
        <div class="form-item">
            <label class="item-label">基金名称<span class="check-tips">（以交易所公布的基金名称为准）</span></label>
            <div class="controls">
            	<input type="text" class="text input-large" name="fund_name" value="{$fund.fund_name|default=''}"/>
            </div>
        </div>
        
        <!--<div class="form-item">-->
            <!--<label class="item-label">区域代码<span class="check-tips">（用于标识基金的上市地点）</span></label>-->
            <!--<div class="controls">-->
            	 <!--<select name="section_code" class="input-large">-->
            		<!--<foreach name="Think.config.FUND_SECTION_CODE" key="key" item="val">-->
            			<!--<notempty name="fund">-->
		            		<!--<if condition="$key eq $fund['section_code']">-->
				           		<!--<option value="{$key}" selected>{$val}</option>-->
				           	<!--<else />-->
		            			<!--<option value="{$key}">{$val}</option>-->
		            		<!--</if>-->
            			<!--<else />-->
            				<!--<option value="{$key}">{$val}</option>-->
            			<!--</notempty>-->
            		<!--</foreach>-->
            	<!--</select>-->
            <!--</div>-->
        <!--</div>-->
        
        <div class="form-item">
            <label class="item-label">基金类型<span class="check-tips"></span></label>
            <div class="controls">
            	 <select name="fund_type" class="input-large">
            		<foreach name="Think.config.FUND_TYPE" key="key" item="val">
            			<notempty name="fund">
		            		<if condition="$key eq $fund['fund_type']">
				           		<option value="{$key}" selected>{$val}</option>
				           	<else />
		            			<option value="{$key}">{$val}</option>
		            		</if>
            			<else />
            				<option value="{$key}">{$val}</option>
            			</notempty>
            		</foreach>
            	</select>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">基金产品合同<span class="check-tips"></span></label>
            <div class="controls">
            	 <select name="contract_id" id="contract_id" class="input-large">
            	 	<option value="0">请选择</option>
            		<foreach name="contractList" key="key" item="val">
            			<notempty name="fund">
		            		<if condition="$val['id'] eq $fund['contract_id']">
				           		<option value="{$val['id']}" selected>{$val.name}</option>
				           	<else />
		            			<option value="{$val['id']}">{$val.name}</option>
		            		</if>
            			<else />
            				<option value="{$val['id']}">{$val.name}</option>
            			</notempty>
            		</foreach>
            	</select>
            	<input type="hidden" name="contract_name" id="contract_name" value="{$fund.contract_name|default=''}"/>
            </div>
        </div>
        
        <div class="form-item">
            <label class="item-label">基金经理<span class="check-tips"></span></label>
            <div class="controls">
            	 <select name="trader_id" id="trader_id" class="input-large">
            	 	<option value="0" selected>请选择</option>
            		<foreach name="traderList" key="key" item="val">
            			<notempty name="fund">
		            		<if condition="$val['id'] eq $fund['trader_id']">
				           		<option value="{$val['id']}" selected>{$val.name}</option>
				           	<else />
		            			<option value="{$val['id']}">{$val.name}</option>
		            		</if>
            			<else />
            				<option value="{$val['id']}">{$val.name}</option>
            			</notempty>
            		</foreach>
            	</select>
            	
            	<input type="hidden" name="trader_name" id="trader_name" value="{$fund.trader_name|default=''}"/>
            </div>
        </div>
        
        <!--<div class="form-item">-->
            <!--<label class="item-label">基金分类<span class="check-tips"></span></label>-->
            <!--<div class="controls">-->
            	<!--<span id="cat_names"></span>-->
            	<!--<span id="cat_sel_p"></span>-->
            	<!--<span id="cat_sel_s"></span>-->
            <!--</div>-->
            <!--<input type="hidden" name="cat_ids" id="cat_ids" value=""/>-->
            <!--<input type="hidden" name="cat_names" id="cat_names1" value=""/>-->
        <!--</div>-->
        <!-- -->
        <div class="form-item">
            <label class="item-label">成分股标题<span class="check-tips"></span></label>
            <div class="controls">
            	<input type="text" class="text input-large" name="avatar_title" value="{$fund.avatar_title|default=''}"/>
            </div>
        </div>
	<div class="form-item">
		<label class="item-label">成分股内容<span class="check-tips"></span></label>
		<div class="controls">
			<textarea style="width:900px;height:200px;padding:5px;" class="input-large" name="avatar_content">{$fund.avatar_content|default=''}</textarea>
		</div>
	</div>
        <!-- -->
        <!--<div class="form-item">-->
            <!--<label class="item-label">基金托管费率<span class="check-tips"></span></label>-->
            <!--<div class="controls">-->
            	<!--<input type="text" class="text input-large" name="trusteeship_rate" value="{$fund.trusteeship_rate|default=''}"/> %-->
            <!--</div>-->
        <!--</div>-->
        <!--<div class="form-item">-->
            <!--<label class="item-label">基金管理人<span class="check-tips"></span></label>-->
            <!--<div class="controls">-->
            	<!--<input type="text" class="text input-large" name="fund_admin" value="{$fund.fund_admin|default=''}"/>-->
            <!--</div>-->
        <!--</div>-->
        <!--<div class="form-item">-->
            <!--<label class="item-label">管理费率<span class="check-tips"></span></label>-->
            <!--<div class="controls">-->
            	<!--<input type="text" class="text input-large" name="admin_rate" value="{$fund.admin_rate|default=''}"/> %-->
            <!--</div>-->
        <!--</div>-->
        <div class="form-item">
            <label class="item-label">基金预期收益率<span class="check-tips"></span></label>
            <div class="controls">
            	<input type="text" class="text input-large" name="expected_rate" value="{$fund.expected_rate|default=''}"/> %
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">预期收益率说明<span class="check-tips"></span></label>
            <div class="controls">
            	<textarea style="width:900px;height:200px;padding:5px;" class="input-large" name="expected_rate_desc">{$fund.expected_rate_desc|default=''}</textarea>
            </div>
        </div>
        <!--<div class="form-item">-->
            <!--<label class="item-label">证券投资基金成立时间<span class="check-tips">（基金产品发行时间）</span></label>-->
            <!--<div class="controls">-->
            	<!--<input type="text" class="text input-large date_picker" name="estb_time" value="{$fund.estb_time_format|default=''}"/>-->
            <!--</div>-->
        <!--</div>-->
        <!--<div class="form-item">-->
            <!--<label class="item-label">证券投资基金上市时间<span class="check-tips"></span></label>-->
            <!--<div class="controls">-->
            	<!--<input type="text" class="text input-large date_picker" name="list_time" value="{$fund.list_time_format|default=''}"/>-->
            <!--</div>-->
        <!--</div>-->
        <div class="form-item">
            <label class="item-label">开放期起始日期<span class="check-tips"></span></label>
            <div class="controls">
            	<input type="text" class="text input-large date_picker" name="open_start_time" value="{$fund.open_start_time_format|default=''}"/>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">开放期赎回起始日期<span class="check-tips"></span></label>
            <div class="controls">
            	<input type="text" class="text input-large date_picker" name="open_back_time" value="{$fund.open_back_time_format|default=''}"/>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">开放期结束日期<span class="check-tips"></span></label>
            <div class="controls">
            	<input type="text" class="text input-large date_picker" name="open_end_time" value="{$fund.open_end_time_format|default=''}"/>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">开放日说明<span class="check-tips"></span></label>
            <div class="controls">
            	<textarea style="width:900px;height:200px;padding:5px;" class="input-large" name="open_desc">{$fund.open_desc|default=''}</textarea>
            </div>
        </div>
         <div class="form-item">
            <label class="item-label">封闭期限<span class="check-tips">（针对封闭式基金而言，指其封闭时间）</span></label>
            <div class="controls">
            	<input type="text" class="text input-large" name="std_time" value="{$fund.std_time|default=''}"/>
            	<select name="std_unit">
            		<foreach name="stdUnit" key="key" item="item">
            			<if condition="$fund['std_unit'] eq $key">
            				<option value="{$key}" selected='selected'>{$item}</option>
            			<else/>
	            			<option value="{$key}">{$item}</option>
            			</if>
            		</foreach>
            	</select>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">封闭期说明<span class="check-tips"></span></label>
            <div class="controls">
            	<textarea style="width:900px;height:200px;padding:5px;" class="input-large" name="close_desc">{$fund.close_desc|default=''}</textarea>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">总份数<span class="check-tips"></span></label>
            <div class="controls">
            	<input type="text" class="text input-large" name="total_count" value="{$fund.total_count|default=''}"/>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">开始购买日期<span class="check-tips"></span></label>
            <div class="controls">
            	<input type="text" class="text input-large date_picker" name="trade_time" value="{$fund.trade_time_format|default=''}"/>
            </div>
        </div>
        <!-- <div class="form-item">
            <label class="item-label">最小购买金额<span class="check-tips">（单位元，0表示无限制）</span></label>
            <div class="controls">
            	<input type="text" class="text input-large" name="min_amount" value="{$fund.min_amount|default=''}"/>
            </div>
        </div> -->
        <div class="form-item">
            <label class="item-label">最小购买份数<span class="check-tips"></span></label>
            <div class="controls">
            	<input type="text" class="text input-large" name="min_count" value="{$fund.min_count|default=''}"/>
            </div>
        </div>
        <!-- <div class="form-item">
            <label class="item-label">最大投资金额<span class="check-tips">（单位元，0表示无限制）</span></label>
            <div class="controls">
            	<input type="text" class="text input-large" name="max_amount" value="{$fund.max_amount|default=''}"/>
            </div>
        </div> -->
        <div class="form-item">
            <label class="item-label">最大购买份数<span class="check-tips"></span></label>
            <div class="controls">
            	<input type="text" class="text input-large" name="max_count" value="{$fund.max_count|default=''}"/>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">每份金额<span class="check-tips"></span></label>
            <div class="controls">
            	<input type="text" class="text input-large" name="unit_price" value="{$fund.unit_price|default=''}"/>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">排序<span class="check-tips">（基金产品的显示顺序，整数，越小越靠前）</span></label>
            <div class="controls">
            	<input type="text" class="text input-large" name="sort_order" value="{$fund.sort_order|default=''}"/>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">基金产品描述<span class="check-tips"></span></label>
            <div class="controls">
            	<textarea style="width:900px;height:200px;padding:5px;" class="input-large" name="fund_brief">{$fund.fund_brief|default=''}</textarea>
            </div>
        </div>
        
        <div class="form-item">
            <label class="item-label">是否是推荐基金产品<span class="check-tips"></span></label>
            <div class="controls">
            	 <select name="is_recommend" class="input-large">
            		<foreach name="Think.config.FUND_RECOMMEND" key="key" item="val">
            			<notempty name="fund">
		            		<if condition="$key eq $fund['is_recommend']">
				           		<option value="{$key}" selected>{$val}</option>
				           	<else />
		            			<option value="{$key}">{$val}</option>
		            		</if>
            			<else />
            				<option value="{$key}">{$val}</option>
            			</notempty>
            		</foreach>
            	</select>
            </div>
        </div>
        
        <div class="form-item">
            <label class="item-label">推荐理由<span class="check-tips">（如果是推荐基金产品，需给出推荐理由）</span></label>
            <div class="controls">
            	<textarea style="width:900px;height:200px;padding:5px;" class="input-large" name="recommend_note">{$fund.recommend_note|default=''}</textarea>
            </div>
        </div>
        
        <div class="form-item">
            <button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">确 定</button>
            <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
        </div>
    </form>
</block>
<block name="style">
	<link href="__PUBLIC__/static/jquery-datetimepicker/jquery-datetimepicker.css" rel="stylesheet" media="screen">
</block>
<block name="script">
	<script type="text/javascript" src="__PUBLIC__/static/jquery-datetimepicker/jquery-datetimepicker.js"></script>
    <script type="text/javascript">
    	$(function(){
    		window.fundCatNames = {};
    		window.fundCatIds = {};
    		
    		<notempty name="fund">
    			//查询基金所属的分类信息
    			var fundId = '{$fund.id}';
    			var fundCat = ajaxRequest('{:U("Fund/fundCatRelation")}', {'fund_id':fundId}, {'async':false});
    			var catIds = '';
    			var catNames = '';
    			
    			//初始化基金所属的分类信息
    			if(fundCat && fundCat.error == 0) {
    				$.each(fundCat.msg, function(key, val) {
    					fundCatIds[val['cat_parent_id']] = val['cat_id'];
    					fundCatNames[val['cat_parent_id']] = val['cat_name'];
    					catIds += val['cat_id'] + ',';
    					catNames += val['cat_name'] + ',';
    				});
    				
    				catIds = catIds.substr(0, catIds.length - 1);
        			catNames = catNames.substr(0, catNames.length - 1);
        			$("#cat_ids").val(catIds);
        			$("#cat_names1").val(catNames);
        			$("#cat_names").html('已选择分类：'+catNames);
    			}
    			
    		</notempty>
    		
    		//请求基金父级分类信息
    		var data = ajaxRequest('{:U("Fund/searchCat")}', {'parent_id':-1}, {'async':false});
    		var parent = $("#cat_sel_p");
    		
    		if(data && data.error == 0) {
    			//显示父级分类信息
    			var info = '<select><option value="-1">请选择父级分类</option>';
				$.each(data.msg, function(key, val){
					info += '<option value="'+val.id+'">'+val.name+'</option>';
				});
				info += '</select>';
				parent.empty().append(info);
				var child = $("#cat_sel_s");
				
				//父级分类注册事件
				parent.children('select').change(function(){
            		var pVal = $(this).val();
            		if(pVal == -1) {
            			child.empty();
            			return;
            		}
            		
            		//请求基金子级分类信息
            		data = ajaxRequest('{:U("Fund/searchCat")}', {'parent_id':pVal}, {'async':false});
            		
            		//基金分类信息获取成功
            		if(data.error == 0) {
            			//显示子分类信息
            			info = '<select><option value="-1">请选择子级分类</option>';
        				$.each(data.msg, function(key, val){ 
        					info += '<option value="'+val.id+'">'+val.name+'</option>';
        				});
        				info += '</select>';
        				child.empty().append(info);
    	        		
    	        		//子分类信息注册change事件
    	        		child.children('select').change(function(){
    	        			//已选择分类id
    	        			var ids = window.fundCatIds;
    	        			//已选择分类名称
    	        			var names = window.fundCatNames;
    	        			names[pVal] = child.children('select').find('option:selected').html();
    	        			ids[pVal] = $(this).val();
    	        			
    	        			catNames = '';
    	        			$.each(names, function(key, val){
    	        				catNames += val + ',';
    	        			});

    	        			catIds = '';
    	        			$.each(ids, function(key, val){
    	        				catIds += val + ',';
    	        			});
    	        			
    	        			catIds = catIds.substr(0, catIds.length - 1);
    	        			catNames = catNames.substr(0, catNames.length - 1);
    	        			$("#cat_ids").val(catIds);
    	        			$("#cat_names1").val(catNames);
	        				$("#cat_names").html('已选择分类：'+catNames+'　');
    	        		});
        			} else {
        				child.html(data.msg);
        			} 
            	});
    		} else {
    			parent.html('分类信息查询失败');
    		}
    		
    		//注册基金经理选择事件
    		$("#trader_id").change(function(){
    			var val = $(this).val();
    			var traderName = $("#trader_name");
    			if(val == 0) {
    				traderName.val('');
    				return;
    			}
    			traderName.val($(this).find('option:selected').html());
    		});
    		
    		//注册合同类型选择事件
    		$("#contract_id").change(function(){
    			var val = $(this).val();
    			var contractName = $("#contract_name");
    			if(val == 0) {
    				contractName.val('');
    				return;
    			}
    			contractName.val($(this).find('option:selected').html());
    		});
    	});
    	
    	//日期时间插件
    	$('.date_picker').datetimepicker({
    		lang:'ch',
    		format:'Y-m-d',
    		timepicker:false,
    		allowBlank:true
		});
    	
        //导航高亮
        highlight_subnav('{:U('Fund/fundList')}');
    </script>
</block>
